# 3.2 Sound Sensor ## 3.2.1 Overview The sound sensor, with excellent sound reception, mainly contains a high sensitivity microphone and an LM358 operational amplifier. Weak sound signals are captured by the microphone and amplified by LM358, so the output is clear and recognizable, which can be effectively detected the sounds. This sensor features high sensitivity, fast response speed, so is widely used in sound detection and recognition, providing a stable and reliable voice input solution for various intelligent devices. ## 3.2.2 Schematic Diagram ![t41](./media/t41.png) **Working principle:** If the built-in electret film vibrates after receiving sounds, its capacitance will change to produce a tiny voltage. The LM358 chip is adopted in circuits to amplify the sound signals detected by the high-sensitivity microphone. ## 3.2.3 Code Blocks Blocks in ![](./media/output.png): 1. ![t44](./media/t44.png) displays the input values. It can be used to display any data type supported by MicroBlocks. In addition to directly entering values, a variable report block can also be placed there. If you want to display more than one piece of data, simply click on the triangle to add more. This is one of the main methods to help troubleshoot the faults in the code. Click on ![t47](./media/t47.png) to add an output blank: ![t45](./media/t45.png) 2. ![t42](./media/t42.png) plots input values in a Data Graph. Any type of data can be plotted as a graph: numbers, digital and analog pin input, sensor output, etc. If you want to draw more than one, click on the triangle to add up to six values simultaneously drawn in different colors. Note that plotting is only supported in the IDE. Therefore, it is possible to plot only when a device is connected to the computer. Plotting without a device will result in showing “Not connected to the mainboard”. Click ![t11](./media/t11.png) to check the graph. ![t46](./media/t46.png) ----------------- Blocks in ![](./media/codingBox.png): 1. ![t43](./media/t43.png) is a block included in coding box library. It reads the analog values of the sound sensors in the coding box. ## 3.2.4 Test Code You can manually build blocks, or directly open the code file we provide: `3-2-Sound.ubp`. If you have any questions about how to open code files or upload code, please back to `1.9 Upload Code`. **Build code blocks:** 1. In ![](./media/control.png), drag ![](./media/t1.png) and ![](./media/t2.png) to the script area, and stack them together. ![t34](./media/t34.png) 2. In ![](./media/output.png), drag ![t44](./media/t44.png) and ![t42](./media/t42.png) block and put them in ![](./media/t2.png) respectively. 3. Tap ![t47](./media/t47.png) of the ![t44](./media/t44.png) to add an output blank. Enter `loudness:` in the first one. ![t48](./media/t48.png) 4. In ![](./media/codingBox.png), drag ![t43](./media/t43.png) and put it in both the second blank of ![t48](./media/t48.png) and the ![t42](./media/t42.png). **Complete code:** ![t49](./media/t49.png) ## 3.2.5 Test Result Connect the coding box to the MicroBlocks via USB or Bluetooth, and click ![t59](./media/t59.png) to upload the code to the coding box. Click ![t11](./media/t11.png) to check the graph. Make a sound for the sensor to capture, and then we can see the analog values of the sound on the editor. ![t50](./media/t50.png)